package com.pybox.repository;

import com.pybox.entity.TCabinets;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * 描述：TCabinets Repository
 *
 * @author wuyingkai
 * @date 2018-09-15
 */

public interface TCabinetsRepository extends JpaRepository<TCabinets, Integer>, JpaSpecificationExecutor<TCabinets> {

    @Query(value = "select  *  from t_cabinets where uuid=?1",nativeQuery = true)
    TCabinets findTCabinetsByUuid(String uuid);

    @Query(value = "select  count(1) from t_cabinets where passwd=?1 and customer_id =?2",nativeQuery = true)
    Integer checkCabinetPasswordUnique(String password,Integer customerId);
    @Query(value = "select  *  from t_cabinets where uuid=?1",nativeQuery = true)
    TCabinets getTCabinetsByUuid(String uuid);


    @Query(value = "update TCabinets t set t.isOnline = ?1 where t.id = ?2")
    @Modifying
    @Transactional
    void updateIsOnline(int is_online, int id);
}
